Skip to content

fix(opencode): avoid TTY corruption from double cleanup#16565

Merged
nexxeln merged 2 commits intoanomalyco:devfrom
tobwen:fix/opencode-try-finally-double-cleanup
Mar 8, 2026
Merged

fix(opencode): avoid TTY corruption from double cleanup#16565
nexxeln merged 2 commits intoanomalyco:devfrom
tobwen:fix/opencode-try-finally-double-cleanup

Conversation

@tobwen
Copy link
Contributor

@tobwen tobwen commented Mar 8, 2026

Issue for this PR

Closes #16564

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

When using --continue multiple times and exiting with CTRL+C, the terminal enters an inconsistent state where mouse movements produce escape sequences (e.g. ^[[<35;9734M). This affects terminal emulators like MinTTY (Git Bash) and PuTTY on Windows.

The root cause was a double cleanup introduced in commit 3ebebe0: the tui() call had both onExit: stop as a callback and a finally { await stop() } block outside it. On CTRL+C, stop() was called twice, corrupting the TTY state and leaving mouse tracking active.

Fix: Either set onExit: undefined or remote it (I've done so) so the exit callback no longer calls stop() on its own. The finally block remains as the single cleanup point, ensuring stop() is called exactly once — both on normal exit and on errors.

How did you verify your code works?

Tested manually with multiple --continue runs and CTRL+C exits:

  • Single run exits cleanly
  • Multiple sequential runs produce no stray mouse escape sequences
  • Terminal remains in a consistent state after exit
  • Verified on MinTTY, PuTTY, and Linux terminals

Screenshots / recordings

image

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions
Copy link
Contributor

github-actions bot commented Mar 8, 2026

The following comment was made by an LLM, it may be inaccurate:

I found several related PRs that address similar TTY/terminal corruption issues, though none appear to be exact duplicates of #16565. However, these are worth noting:

Related PRs:

These PRs address similar issues (terminal corruption, mouse tracking, CTRL+C handling on Windows), but PR #16565 appears to be focused on a specific double cleanup bug introduced in a particular commit rather than a duplicate of these existing fixes.

@tobwen tobwen force-pushed the fix/opencode-try-finally-double-cleanup branch from 01ef9d7 to e853c74 Compare March 8, 2026 05:55
@nexxeln nexxeln merged commit 13a68f3 into anomalyco:dev Mar 8, 2026
6 of 8 checks passed
@tobwen tobwen deleted the fix/opencode-try-finally-double-cleanup branch March 8, 2026 16:32
@kommander kommander mentioned this pull request Mar 8, 2026
@Almazick
Copy link

Almazick commented Mar 9, 2026

Same problem here. I just updated to 1.2.22, and OpenCode in the CLI is completely unusable. I don’t understand how this issue has been going on for a week and nobody noticed, when you can’t even use OpenCode at all. In my case nothing run cleanly. Once you open opencode and press ctrl + p, everything goes does the hill.

tallpizza pushed a commit to tallpizza/ontology that referenced this pull request Mar 9, 2026
)

Co-authored-by: Shoubhit Dash <shoubhit2005@gmail.com>
(cherry picked from commit 13a68f3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TUI mouse control characters appear after CTRL+C with --continue

3 participants